package com.shujia.scala

object Demo10Fun {
  def main(args: Array[String]): Unit = {

    /**
      * 以函数作为返回值
      *
      * 在调用一个 函数的时候返回一个函数
      *
      *
      */


    def fun(name: String): String => String = {

      def f(s: String): String = {
        s + "数加" + name
      }

      //返回一个函数
      f
    }


    val f1 = fun("java")

    val str = f1("scala")

    println(str)

    val str1 = fun("java")("scala")


    //函数柯里化

    def fun1(name: String)(s: String): String = {
      s + "数加" + name
    }

    println(fun1("java")("spark"))


    println("=" * 100)
    //偏应用函数

    def fun2(name: String, s: String): String = {
      s + "数加" + name
    }


    fun2("java", "spark")
    fun2("java", "python")
    fun2("java", "shujia")


    val fun3 = fun2("java", _: String)

    println(fun3("spark"))
    println(fun3("scala"))
    println(fun3("shujia"))


  }

}
